package com.hotelvip.controller;

import com.hotelvip.common.interceptor.SecurityParameter;
import com.hotelvip.common.utils.IPUtils;
import com.hotelvip.common.utils.JSONResult;
import com.hotelvip.common.utils.NumberUtil;
import com.hotelvip.entity.SysUser;
import com.hotelvip.entity.TestEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * @author Lzh
 * @date 2020/11/27 15:34
 */
@Api(value = "v1",tags = "测试！！！！")
@RestController
@RequestMapping("/test")
public class TestController {
    @ApiOperation(value = "测试接口",httpMethod = "GET")
    @GetMapping("/api/{api}")
    public JSONResult apiTest(@PathVariable("api") String api){
        String s = ""+new Date()+"==="+api;
        return JSONResult.ok(s);
    }

    @ApiOperation(value = "电话号码验证测试",httpMethod = "POST")
    @PostMapping("/phone")
    @SecurityParameter
    public JSONResult phoneTest(String phone){
        System.out.println(phone);
        if (!NumberUtil.isPhone(phone)){
            return JSONResult.errorMsg("号码错误");
        }
        return JSONResult.ok(phone);
    }

    @PostMapping("/arrays")
    @SecurityParameter
    public JSONResult arraysTest(@RequestBody Map<String,Object> test1){
        System.out.println(test1.get("a"));
        return JSONResult.ok(test1);
    }
    @PostMapping("/userTest")
    @SecurityParameter
    public JSONResult testUser(@RequestBody SysUser user){
        System.out.println(user.toString());
        return JSONResult.ok();
    }
    @ApiOperation(value = "获取ip地址的测试",httpMethod = "GET")
    @GetMapping("/getIp")
    public JSONResult getIp(){
        String ipAddr = IPUtils.getIpAddr();
        return JSONResult.ok(ipAddr);
    }
    @ApiOperation(value = "测试接口1")
    @RequestMapping(value = "/test01",method = RequestMethod.POST)

    public JSONResult apiTest1(){
        String s = ""+new Date();
        return JSONResult.ok(s);
    }
    @ApiOperation(value = "枚举测试",httpMethod = "GET")
    @GetMapping("/testEnum")
    public JSONResult testEnum(){
        TestEnum testEnum = new TestEnum().setId(1).setName("zhagsan").setSex(1);
        return JSONResult.ok(testEnum);

    }

    @ApiOperation(value = "数组",httpMethod = "GET")
    @GetMapping("/testGET")
    public JSONResult testGET(String id,String[] key){
//        TestEnum testEnum = new TestEnum().setId(1).setName("zhagsan").setSex(1);

        return JSONResult.ok(id+key);

    }

}
